package be.robotscrapyard;

import com.google.wave.api.AbstractRobotServlet;
import com.google.wave.api.Blip;
import com.google.wave.api.Event;
import com.google.wave.api.RobotMessageBundle;
import com.google.wave.api.TextView;
import com.google.wave.api.Wavelet;

@SuppressWarnings("serial")
public class Waalbot extends AbstractRobotServlet
{
	private String[] replys = {"Non", "Je ne veut pas travailler", "Je ne comprends pas", "Sale flamand"};
	@Override
	public void processEvents(RobotMessageBundle bundle)
	{
		Wavelet wave = bundle.getWavelet();
		
		if(bundle.wasSelfAdded())
		{
			Blip blip = wave.appendBlip();
			TextView textView = blip.getDocument();
			textView.append("Bonjour je m'appelle waalbot.");
			textView.append("Pour me faire travailler, typez 'travaille'.");
			return;
		}
		
		for(Event e: bundle.getBlipSubmittedEvents())
		{
			Blip blip = e.getBlip();
			if(blip.getDocument().getText().equals("travaille"))
			{
				Blip reply = blip.createChild();
				TextView textView = reply.getDocument();
				textView.append(randomReply());
			}		
		}
	}
	
	public String randomReply()
	{
		int i = (int)(Math.random() * replys.length);
		return replys[i];
	}

}
